﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="打印.aspx.cs" Inherits="FancyIdea.PingShui.view.打印" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <style type="text/css">
        body
        {
            margin: 0;
        }
        img
        {
            width: 208;
            height: 296mm;
            position: relative;
            left: 0mm;
            top: 0mm;
            z-index: -10;
        }
        table#ContentTable
        {
            border-collapse: collapse;
            table-layout: fixed;
            width: 166mm;
            position: absolute;
            left: 19mm;
            top: 133mm;
            border: 1px solid black;
        }
        table#ContentTable tr
        {
            height: 8.7mm;
        }
        table#ContentTable td
        {
            background: url("t.png") repeat;
            border: 0px solid gray;
            font-size: 3.2mm;
            padding: 0 1mm;
        }
        span[id], .print
        {
            position: absolute;
            font-size: 6mm;
        }
        .hide
        {
            display: none;
        }
    </style>
    <style media="print" type="text/css">
        table#ContentTable, table#ContentTable td
        {
            border: 0;
        }
    </style>
    <meta name="GENERATOR" content="MSHTML 9.00.8112.16437" />
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/app.js"></script>
</head>
<body>
    <img src="b.jpg" />
    <form id="MainForm" runat="server" style="width: 800px;">
    <div>
        <input id="__VIEWSTATE" name="__VIEWSTATE" value="/wEPDwULLTE0MTE1MDc0NTYPZBYCAgMPZBYSAgEPDxYCHgRUZXh0BQNhc2RkZAIDDw8WAh8ABQQ2MDAwZGQCBQ8PFgIfAAUEMjAxMWRkAgcPDxYCHwAFAjExZGQCCQ8PFgIfAAUBMWRkAgsPDxYCHwAFBDIwMTFkZAINDw8WAh8ABQIxMWRkAg8PDxYCHwAFAjMwZGQCEQ9kFghmD2QWCGYPDxYCHwAFBueojuenjWRkAgEPDxYCHwAFEuW6lOe6s+eojue7j+iQpeminWRkAgIPDxYCHwAFEeeojueOhyjlvoHmlLbnjocpZGQCAw8PFgIfAAUL56iO6aKdKOWFgylkZAIBD2QWCGYPDxYCHwAFBumHkeiejWRkAgEPDxYCHwAFBDYwMDBkZAICDw8WAh8ABQE1ZGQCAw8PFgIfAAUFMzAwLjBkZAICD2QWCGYPDxYCHwAFLOS8geS6i+S4muWNleS9jeaJv+WMheOAgeaJv+enn+e7j+iQpeaJgOW+lzElZGQCAQ8PFgIfAAUENjAwMGRkAgIPDxYCHwAFATFkZAIDDw8WAh8ABQQ2MC4wZGQCAw9kFghmDw8WAh8ABSnpnZ7luILljLrjgIHljr/ln47jgIHplYco5aKe5YC856iO6ZmE5b6BKWRkAgEPDxYCHwAFBDYwMDBkZAICDw8WAh8ABQExZGQCAw8PFgIfAAUENjAuMGRkZG6wvnINIVwYyif8T0/JWwVYjNxJ"
            type="hidden" />
    </div>
    <table>
        <tr>
            <td colspan="2">
                <strong class="hide">FCDS-QR-164</strong>
            </td>
        </tr>
        <tr>
            <td class="style3" colspan="2">
                <strong class="hide">绵阳市涪城区地方税务局</strong>
            </td>
        </tr>
        <tr>
            <td class="style4" colspan="2" style="text-align: center">
                <strong class="hide">核定定额通知书</strong>
            </td>
        </tr>
        <tr>
            <td class="style5" colspan="2" style="text-align: center">
                <span class="hide">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ________税核[&nbsp;&nbsp;&nbsp;
                    ]号</span>
            </td>
        </tr>
        <tr>
            <td class="style6" colspan="2">
                &nbsp;
                <asp:Label ID="lblName" class="print" Style="left: 18mm; top: 69mm;" runat="server"
                    Font-Bold="False" Text="姓名"></asp:Label>
                <span class="hide">(纳税人):</span>
            </td>
        </tr>
        <tr>
            <td class="style5" colspan="2">
                <span class="hide">&nbsp;&nbsp;&nbsp;&nbsp; 根据《中华人民共和国税收征收管理法》、《中华人民共和国税收征收管理法实施细则》以及相关规定，经审核你户月应纳税额为</span><asp:Label
                    ID="lblMoney" runat="server" Font-Bold="False"  class="print"
                    Style="left: 18mm; top: 97mm;" Text="执行定额"></asp:Label>
                <span class="hide">元（分税种税额见下表）。请按规定的期限申报缴纳应纳税款。本通知自</span><asp:Label ID="lblStartYear"
                    runat="server" Font-Bold="False"  Style="left: 40mm; top: 107mm"
                    Text="起始年"></asp:Label>
                <span class="hide">年</span><asp:Label ID="lblStartMonth" runat="server" Font-Bold="False"
                     Style="left: 60mm; top: 107mm" Text="起始月"></asp:Label>
                <span class="hide">月</span><asp:Label ID="lblStartDay" runat="server" Font-Bold="False"
                     Style="left: 75mm; top: 107mm" Text="起始日"></asp:Label>
                <span class="hide">日起至</span><asp:Label ID="lblEndYear" runat="server" Font-Bold="False" 
                    Style="left: 101mm; top: 107mm" Text="结束年"></asp:Label>
                <span class="hide">年</span><asp:Label ID="lblEndMonth" runat="server" Font-Bold="False" 
                    Style="left: 120mm; top: 107mm" Text="结束月"></asp:Label>
                <span class="hide">月</span><asp:Label ID="lblEndDay" runat="server" Font-Bold="False" 
                    Style="left: 135mm; top: 107mm" Text="结束日"></asp:Label>
                <span class="hide">日止执行。</span>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center">
                <strong><span class="hide">应纳税额明细表</span></strong><br />
                <asp:Table ID="ContentTable" runat="server" BorderStyle="None">
                </asp:Table>
            </td>
        </tr>
        <tr>
            <td>
                <span class="hide">纳税人(签章):</span><br class="style5" />
                <span class="hide">&nbsp;&nbsp;&nbsp;&nbsp; 年&nbsp; 月&nbsp; 日</span>
            </td>
            <td>
                <span class="hide">税务机关(签章):</span><br class="style5" />
                <span class="hide">&nbsp;&nbsp;&nbsp;&nbsp; 年&nbsp; 月&nbsp; 日</span>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="hide">
                告知事项：<br />
                1、定额执行期间内，如你户月应纳税经营额超过税务机关的核定定额百分之二十的应当在法律、行政法规规定的申报期限内，向主管税务机关进行申报并缴纳税款。<br />
                2、定期定额户应当在定额执行期满后___日内，以该期每月实际发生的经营额、所得额向主管税务机关进行分月汇总申报。<br />
                3、不按规定的期限进行申报或缴纳应纳税款的，税务机关将依法予以处罚。<br />
                此表一式三联：一联主管税务机关留存（黑） 二联 纳税人留存（红）三联&nbsp; 征税出留存（绿）
            </td>
        </tr>
    </table>
    <div id="project" runat="server" style="display: none">
    </div>
    <div id="item" runat="server" style="display: none">
    </div>
    </form>
    <div class="item_panel" style="display: none">
        <select class="s_project">
        </select>
        <select class="s_item">
        </select>
        <input type="button" class="s_ok" value="确定" />
        <input type="button" class="s_cancel" value="取消" />
        <input type="button" class="s_clear" value="清除" />
    </div>
    <input type="text" class="item_edit" style="display: none" />
</body>
<script type="text/javascript">
    function digit_uppercase(n) {
        var fraction = ['角', '分'];
        var digit = [
            '零', '壹', '贰', '叁', '肆',
            '伍', '陆', '柒', '捌', '玖'
        ];
        var unit = [
            ['元', '万', '亿'],
            ['', '拾', '佰', '仟']
        ];
        var head = n < 0 ? '欠' : '';
        n = Math.abs(n);
        var s = '';
        for (var i = 0; i < fraction.length; i++) {
            s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
        }
        s = s || '整';
        n = Math.floor(n);
        for (var i = 0; i < unit[0].length && n > 0; i++) {
            var p = '';
            for (var j = 0; j < unit[1].length && n > 0; j++) {
                p = digit[n % 10] + unit[1][j] + p;
                n = Math.floor(n / 10);
            }
            s = p.replace(/(零.)*零$/, '')
             .replace(/^$/, '零')
          + unit[0][i] + s;
        }
        return head + s.replace(/(零.)*零元/, '元')
                   .replace(/(零.)+/g, '零')
                   .replace(/^整$/, '零元整');
    }
</script>
<script type="text/javascript">
    var projects = {};
    $(function () {
        // 引用itemPanel和itemEdit，因为它们detach了之后将不能通过上下文找到
        window.itemPanel = $("div.item_panel").detach().show();
        window.itemEdit = $("input.item_edit").detach().show();

        // 构建project数据结构
        $("div#project span").each(function () {
            var code = $(this).attr("code");
            var text = $(this).text();
            projects[code] = {
                text: text,
                items: [],
                toString: function () { return this.text; }
            };
        });

        // 构建item数据结构
        $("div#item span").each(function () {
            var code = $(this).attr("code");
            var text = $(this).text();
            var rate = $(this).attr("zssl");
            var parentCode = $(this).attr("project_code");

            var project = projects[parentCode];
            if (!project) { return; }

            project.items.push({
                text: text,
                rate: rate,
                toString: function () { return this.text; }
            });
        });

        var keys = [];
        for (var key in projects) { keys.push(key); }
        keys.sort();
        for (var i = 0; i < keys.length; i++) {
            project = projects[keys[i]];
            $("<option>").val(keys[i]).text(project.toString()).appendTo(itemPanel.find(".s_project"));
        }

        itemPanel.find(".s_item").change(function () {
            var rate = $(this).find("option:selected").attr("rate");
            var tr = itemPanel.parentsUntil("tr").parent("tr");
            tr.find("td:eq(2)").text(rate);
        });

        itemPanel.find(".s_project").change(function () {
            var projectCode = $(this).find("option:selected").val();
            var project = projects[projectCode];
            itemPanel.find(".s_item").empty();
            $.each(project.items, function (index, item) {
                $("<option>").text(item.toString())
                    .attr("rate", item.rate || "0")
                    .appendTo(itemPanel.find(".s_item"));
            });
            itemPanel.find(".s_item").change();
        }).change();

        // 将选择的数据保存在TR的data缓存中
        var saveData = function () {
            var tr = itemPanel.parentsUntil("tr").parent("tr");
            tr.data("p_code", itemPanel.find(".s_project option:selected").val());
            tr.data("i_code", itemPanel.find(".s_item option:selected").val());
            tr.data("i_text", itemPanel.find(".s_item option:selected").text());
            tr.data("i_rate", itemPanel.find(".s_item option:selected").attr("rate"));
            tr.data("i_amount", itemEdit.val());
            return tr;
        };

        var sum = function () {
            var sum = 0;
            $("table#ContentTable tr").find("td:eq(3)").each(function () {
                var n = Number($(this).text());
                if (isNaN(n)) { n = 0; }
                sum += n;
            });
            $("table#ContentTable tr:last td:last").text(digit_uppercase(sum));
        };

        var resetData = function (tr) {
            tr.find("td:first").text(tr.data("i_text"));
            tr.find("td:eq(1)").text(tr.data("i_amount"));
            tr.find("td:eq(2)").text(tr.data("i_rate"));

            var r = tr.data("i_amount") * tr.data("i_rate") / 100;
            tr.find("td:eq(3)").text(r);

            sum();
        };

        var loadData = function () {
            var tr = itemPanel.parentsUntil("tr").parent("tr");
            var projectCode = tr.data("p_code");
            if (!projectCode) {
                itemPanel.find(".s_item").change();
                itemEdit.val("");
                return;
            }

            itemEdit.val(tr.data("i_amount") || "");

            itemPanel.find(".s_project option").each(function () {
                if (projectCode === $(this).val()) {
                    $(this).attr("selected", true);
                    itemPanel.find(".s_project").change();
                    return false;
                }
            });

            var itemCode = tr.data("i_code");
            if (!itemCode) {
                itemPanel.find(".s_item").change();
                return;
            }

            itemPanel.find(".s_item option").each(function () {
                if (itemCode === $(this).val()) {
                    $(this).attr("selected", true);
                    return false;
                }
            });

            itemPanel.find(".s_item").change();
            return tr;
        };

        var onOk = function () {
            setTimeout(function () {
                var tr = saveData();
                itemPanel.detach();
                itemEdit.detach();
                resetData(tr);
            }, 50);
        };

        itemEdit.keypress(function (event) {
            if (event.keyCode === 13) {
                onOk();
                event.preventDefault();
            }
        }).keydown(function (event) {
            if (event.altKey || event.ctrlKey) {
                return;
            }

            if (isCtrlKey(event.keyCode)) {
                return;
            }

            var ch = keyChar(event);
            if (/[0-9\.]/.test(ch)) { return; }
            else { return false; }
        });

        itemPanel.find(".s_ok").click(onOk);

        itemPanel.find(".s_cancel").click(function () {
            var me = $(this);
            setTimeout(function () {
                var tr = me.parentsUntil("tr").parent("tr");
                itemPanel.detach();
                itemEdit.detach();
                resetData(tr);
            }, 50);
        });

        itemPanel.find(".s_clear").click(function () {
            var me = $(this);
            setTimeout(function () {
                var tr = me.parentsUntil("tr").parent("tr");
                itemPanel.detach();
                itemEdit.detach();
                tr.find("td:first").empty();
            }, 50);
        });

        $("table#ContentTable tr:not(:first)").find("td:first, td:eq(1)").click(function () {
            if (itemPanel.is(":visible")) {
                return;
            }

            var tr = $(this).parent("tr");
            itemPanel.appendTo(tr.find("td:first").html(""));
            itemEdit.appendTo(tr.find("td:eq(1)").html(""));
            loadData();

            if ($(this).index() === 1) {
                itemEdit.focus();
            }
        });

        $(function () {
            sum();
            $("table#ContentTable tr").find("td:first").css("width", "40mm")
                .end().find("td:eq(1)").css("width", "42mm")
                .end().find("td:eq(2)").css("width", "40mm")
                .end().find("td:eq(3)").css("width", "42mm");
        });
    });
</script>
</html>
